<script setup lang="ts">
import { ref, defineEmits } from "vue";
import { trimHostDto, trimHostArgus } from "@/api/vap/cluster";

const emit = defineEmits(["onSearchEnv"]);
const onSearchTable = () => {
  emit("onSearchEnv");
};

const hostForm = ref<trimHostDto>();
const dialogVisible = ref(false);

const showTrimDialog = (row: any) => {
  console.log(row);
  hostForm.value = {
    hostId: row.id,
    hostname: row.hostName,
    ip: row.ip,
    guaIp: row.guaIp,
    guaPort: row.guaPort,
    guaProtocol: row.guaProtocol
  };
  dialogVisible.value = true;
};
const onSubmit = () => {
  trimHostArgus(hostForm.value).then(() => {
    dialogVisible.value = false;
    onSearchTable();
  });
};
defineExpose({
  showTrimDialog
});
</script>

<template>
  <el-dialog v-model="dialogVisible" title="微调主机信息">
    <el-form ref="elForm" :model="hostForm" label-width="100px">
      <el-form-item label="主机名称" prop="hostname">
        <el-input
          v-model="hostForm.hostname"
          :maxlength="20"
          show-word-limit
          disabled
          :style="{ width: '100%' }"
        />
      </el-form-item>
      <el-form-item label="主机IP" prop="ip">
        <el-input
          v-model="hostForm.ip"
          :maxlength="20"
          show-word-limit
          disabled
          :style="{ width: '100%' }"
        />
      </el-form-item>
      <el-form-item label="guaIp" prop="guaIp">
        <el-input
          v-model="hostForm.guaIp"
          :maxlength="20"
          show-word-limit
          clearable
          :style="{ width: '100%' }"
        />
      </el-form-item>
      <el-form-item label="guaPort" prop="guaPort">
        <el-input
          v-model="hostForm.guaPort"
          :maxlength="20"
          show-word-limit
          clearable
          :style="{ width: '100%' }"
        />
      </el-form-item>
      <el-form-item label="协议" prop="guaProtocol">
        <el-input
          v-model="hostForm.guaProtocol"
          clearable
          :style="{ width: '100%' }"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="onSubmit"> 提交 </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<style scoped></style>
